<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:shiro="http://shiro.apache.org/tags"
    template="../../templates/plantilla.xhtml">

	<ui:define name="content">
		<shiro:hasAnyPermission name="mis_creditos:consultar">
			<h:form id="formularioBase">
				<p:panel header="#{etq['sifeap.missolicitudescredito.titulo']}" style="width:100%; text-align:left;">
					<div align="center">
						<h:panelGrid columns="5" style="width:70%;text-align:left;" id="panelFechas" columnClasses="column-template1">
							<h:outputText value="#{etq['sifeap.missolicitudescredito.inicio']}" />
							<p:calendar id="inicio" value="#{misSolicitudesCreditoManagedBean.solicitudCreditoVo.fechaInicio}" navigator="true" readonlyInput="true" pattern="dd-MM-yyyy" locale="es" />
							<p:spacer width="18px" height="1px" />
							
							<h:outputText value="#{etq['sifeap.missolicitudescredito.fin']}" />
							<p:calendar id="fin" value="#{misSolicitudesCreditoManagedBean.solicitudCreditoVo.fechaFin}" navigator="true" readonlyInput="true" pattern="dd-MM-yyyy" locale="es" />
						</h:panelGrid>
						<h:panelGrid columns="2" style="width:70%;text-align:left;" id="panelEstadoSolicitud" columnClasses="column-template1">
							<h:outputText value="#{etq['sifeap.missolicitudescredito.estado']}" />
							<p:selectOneMenu id="estadoSolicitud" value="#{misSolicitudesCreditoManagedBean.solicitudCreditoVo.solicitudCredito.estadoscredito.idEstadoCredito}" style="width:162px" panelStyle="width:162px">
					            <f:selectItem itemLabel="#{etq['sifeap.seleccion']}" itemValue="#{null}" />  
					            <f:selectItems value="#{misSolicitudesCreditoManagedBean.itemsEstadosCredito}" />  
					        </p:selectOneMenu>
						</h:panelGrid>
					
						<h:panelGrid columns="2" id="panelBoton">
							<p:commandButton actionListener="#{misSolicitudesCreditoManagedBean.consultar}" value="#{etq['sifeap.consultar']}" update="@form, listaSolicitudes"/>
							
							<p:commandButton action="#{misSolicitudesCreditoManagedBean.limpiar}" value="#{etq['sifeap.limpiar']}" update="@form" />
						</h:panelGrid>
					</div>
					
					<h:panelGrid columns="1" id="resultadosPanel" style="width:100%;" rendered="#{misSolicitudesCreditoManagedBean.mostrarResultados}">
						<p:dataTable value="#{misSolicitudesCreditoManagedBean.listaSolicitudes}" widgetVar="listaSolicitudes"
							var="solicitud" id="listaSolicitudes" paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom" rows="10">
							<p:column headerText="#{etq['sifeap.missolicitudescredito.fechasolicitud']}" style="white-space: normal;">
								<h:outputText value="#{solicitud.fechaSolicitud}" >
									<f:convertDateTime pattern="dd-MM-yyyy"/>
								</h:outputText>
							</p:column>
							<p:column headerText="#{etq['sifeap.missolicitudescredito.tipocredito']}" style="white-space: normal;">
								<h:outputText value="#{solicitud.tiposcredito.nombre}" />
							</p:column>
							<p:column headerText="#{etq['sifeap.missolicitudescredito.montosolicitado']}">
								<h:outputText value="#{solicitud.montoSolicitado}" >
									<f:convertNumber currencySymbol="$" currencyCode="COP" groupingUsed="true" type="currency" maxFractionDigits="0" />
								</h:outputText>
							</p:column>
							<p:column headerText="#{etq['sifeap.missolicitudescredito.plazo']}">
								<h:outputText value="#{solicitud.plazo}" />
							</p:column>
							<p:column headerText="#{etq['sifeap.missolicitudescredito.estado']}">
								<h:outputText value="#{solicitud.estadoscredito.nombre}" />
							</p:column>
							
							<shiro:hasAnyPermission name="solicitar_credito:editar,solicitar_credito:detallar">
								<p:column style="text-align:center">
									<shiro:hasPermission name="solicitar_credito:editar">
										<p:commandLink id="btnEditar" 
											action="#{misSolicitudesCreditoManagedBean.cargarEditar}"
											process="@this"
											rendered="#{solicitud.estadoscredito.idEstadoCredito == 1}">
											<f:param value="#{solicitud.idSolicitudCredito}"
												name="p_idsolicitud_edit" id="p_idsolicitud_edit" />
											<h:graphicImage library="images" name="editar.png"
												style="width: 18; height: 18; border: 0px;"
												alt="#{etq['sifeap.editar']}"
												title="#{etq['sifeap.editar']}" />
										</p:commandLink>
									</shiro:hasPermission>
									
									<shiro:hasPermission name="solicitar_credito:detallar">
										<p:commandLink id="btnDetalle" 
											action="#{misSolicitudesCreditoManagedBean.cargarDetalle}"
											process="@this"
											rendered="#{solicitud.estadoscredito.idEstadoCredito != 1}">
											<f:param value="#{solicitud.idSolicitudCredito}"
												name="p_idsolicitud_det" id="p_idsolicitud_det" />
											<h:graphicImage library="images" name="detalle.png"
												style="width: 18; height: 18; border: 0px;"
												alt="#{etq['sifeap.verdetalle']}"
												title="#{etq['sifeap.verdetalle']}" />
										</p:commandLink>
									</shiro:hasPermission>
								</p:column>
							</shiro:hasAnyPermission>
							
							<shiro:hasPermission name="mis_creditos:cancelar">
								<p:column style="text-align:center">
									<p:commandLink id="btnCancelar"
										actionListener="#{misSolicitudesCreditoManagedBean.cargarCancelarSolicitud}"
										process="@this"
										oncomplete="dialogCancelar.show()" 
										disabled="#{solicitud.estadoscredito.idEstadoCredito != 1}">
										<f:param value="#{solicitud.idSolicitudCredito}"
											name="p_idsolicitud_canc" id="p_idsolicitud_canc" />
										<h:graphicImage library="images" name="cancelar.png"
											style="width: 18; height: 18; border: 0px;"
											alt="#{etq['sifeap.missolicitudescredito.cancelar']}"
											title="#{etq['sifeap.missolicitudescredito.cancelar']}" />
									</p:commandLink>
								</p:column>
							</shiro:hasPermission>
							
							<shiro:hasPermission name="solicitar_credito:enviar">
								<p:column style="text-align:center">
									<p:commandLink id="btnEnviar" 
										actionListener="#{misSolicitudesCreditoManagedBean.cargarEnviarEstudio}"
										process="@this"
										oncomplete="dialogEnviar.show()"
										disabled="#{solicitud.estadoscredito.idEstadoCredito != 1}">
										<f:param value="#{solicitud.idSolicitudCredito}"
											name="p_idsolicitud_env" id="p_idsolicitud_env" />
										<h:graphicImage library="images" name="enviar.png"
											style="width: 16; height: 16; border: 0px;"
											alt="#{etq['sifeap.enviarestudio']}"
											title="#{etq['sifeap.enviarestudio']}" />
									</p:commandLink>
								</p:column>
							</shiro:hasPermission>
							
						</p:dataTable>
					</h:panelGrid>
				</p:panel>
				
				<p:confirmDialog id="dialogCancelar"
					message="#{msj['sifeap.missolicitudescredito.cancelar.confirmacion']}"
					header="SIFEAP" widgetVar="dialogCancelar"
					severity="alert">
					<h:panelGroup style="display:block; text-align:center">
						<p:commandButton id="aceptarCancelar"
							value="#{etq['sifeap.aceptar']}"
							update="@form"
							onclick="dialogCancelar.hide()" process="@this"
							actionListener="#{misSolicitudesCreditoManagedBean.cancelarSolicitud}" />
	
						<p:commandButton id="cancelarCancelar"
							value="#{etq['sifeap.cancelar']}"
							action="#{misSolicitudesCreditoManagedBean.cancelar}"
							onclick="dialogCancelar.hide()" process="@this" />
					</h:panelGroup>
				</p:confirmDialog>
				
				<p:confirmDialog id="dialogEnviar"
					message="#{msj['sifeap.missolicitudescredito.enviar.confirmacion']}"
					header="SIFEAP" widgetVar="dialogEnviar"
					severity="alert">
					<h:panelGroup style="display:block; text-align:center">
						<p:outputLabel escape="false" value="#{msj['sifeap.missolicitudescredito.enviar.nota']}" />
					</h:panelGroup>
					<h:panelGroup style="display:block; text-align:center">
						<p:spacer width="1px" height="10px" />
					</h:panelGroup>
					<h:panelGroup style="display:block; text-align:center">
						<p:commandButton id="aceptarEnviar"
							value="#{etq['sifeap.aceptar']}"
							update="@form"
							onclick="dialogEnviar.hide()" process="@this"
							actionListener="#{misSolicitudesCreditoManagedBean.enviarSolicitud}" />
	
						<p:commandButton id="cancelarEnviar"
							value="#{etq['sifeap.cancelar']}"
							action="#{misSolicitudesCreditoManagedBean.cancelar}"
							onclick="dialogEnviar.hide()" process="@this" />
					</h:panelGroup>
				</p:confirmDialog>
			</h:form>
		</shiro:hasAnyPermission>
		
		<p:panel header="#{etq['sifeap.missolicitudescredito.titulo']}" style="width:100%; text-align:left;" rendered="#{!misSolicitudesCreditoManagedBean.tienePermisos}">
			<ui:include src="/templates/denegado.xhtml" />
		</p:panel>
		
	</ui:define>
</ui:composition>
